import { ResponseInterceptor } from './../../../interceptor/response/response.interceptor';
import { ToolsService } from './../../../service/tools/tools.service';
import config from 'src/config/config';
import { Controller, Post, UploadedFile, UploadedFiles, UseInterceptors } from '@nestjs/common';
import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express';

@Controller(`${config.adminPath}/upload`)
@UseInterceptors(ResponseInterceptor)
export class UploadController {
    constructor(private readonly toolsService: ToolsService) {}
    @Post()
    @UseInterceptors(FileInterceptor('file'))
    async uploadFile(@UploadedFile() file) {
        return await this.toolsService.uploadFile(file);
    }

    @Post('/many')
    @UseInterceptors(FilesInterceptor('files'))
    async uploadFiles(@UploadedFiles() files) {
        files.forEach(async (file) => {
            await this.toolsService.uploadFile(file);
        });
        return;
    }
}
